﻿using Microsoft.AspNetCore.Mvc;
using Shop.ProductService.Services;
using Shop.ProductService.Services.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Ocelot.ApiGateway.Controllers
{
    /// <summary>
    /// 应用层控制器
    /// </summary>
    [ApiController]
    [Route("api/app/product")]
    public class IndexController : AbpController, IProductService
    {
        /// <summary>
        /// 此处IProductService服务中的命名空间需要保持与微服务Shop.ProductService一致
        /// </summary>
        public IProductService productService { get; set; }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ProductDto> CreateAsync(ProductDto input)
        {
           return await productService.CreateAsync(input);
        }

        [HttpDelete]
        public async Task DeleteAsync(Guid id)
        {
            await productService.DeleteAsync(id);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet("id")]
        public async Task<ProductDto> GetAsync(Guid id)
        {
             return await productService.GetAsync(id);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return await productService.GetListAsync(input);
        }
 
        [HttpGet("GetProducts")]
        public async Task<List<ProductDto>> GetProductsAsync()
        {
            //1、查询商品
            Console.WriteLine("查询商品。。。网关层执行。。。");
            return await productService.GetProductsAsync();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
        {
            return await productService.UpdateAsync(id, input);
        }
    }
}
